//
//  HZ_more_ViewController.m
//  HZ_Beautiful_Music
//
//  Created by dllo on 16/4/6.
//  Copyright © 2016年 ui. All rights reserved.
//

#import "HZ_more_ViewController.h"
#import "HZ_more_TableViewCell.h"
#import "HSAFNetTool.h"
#import "HZ_more_Model.h"
#import "HZ_more_wab_ViewController.h"
@interface HZ_more_ViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) UITableView *table;
@property (nonatomic, strong) NSMutableArray *dataArray;
@end

@implementation HZ_more_ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
     self.view.backgroundColor = [UIColor orangeColor];
    
    self.table = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    [self.table registerClass:[HZ_more_TableViewCell class] forCellReuseIdentifier:@"HZ_more_TableViewCell"];
    
    _table.delegate = self;
    _table.dataSource = self;
    _table.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.table];
    [self moreData];
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    
    return _dataArray.count;
    
    
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    HZ_more_TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HZ_more_TableViewCell"];
    
    cell.model = _dataArray[indexPath.row];
    
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    return self.view.bounds.size.height / 3;
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    HZ_more_wab_ViewController *wab = [[HZ_more_wab_ViewController alloc] init];
    
    HZ_more_Model *model = _dataArray[indexPath.row];
    
    wab.string = model.actionUrl;
    [self.navigationController pushViewController:wab animated:YES];
    
    [_table deselectRowAtIndexPath:indexPath animated:YES];
}


-(void)moreData{
    
    
    [HSAFNetTool GETNetWithUrl:@"http://api.dongting.com/misc/musiczone/new" body:nil headerFile:nil response:HSJSON success:^(id result) {
        
        self.dataArray = [NSMutableArray arrayWithCapacity:0];
        for (NSDictionary *dic in result[@"data"]) {
            
            HZ_more_Model *model = [[HZ_more_Model alloc] init];
            
            [model setValuesForKeysWithDictionary:dic];
            
            [_dataArray addObject:model];
            
        }
        
        [_table reloadData];
        
    } failure:^(NSError *error) {
        
    }];
    
    
    
    
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
